/**
 * Descriptions：
 * <p>
 * Author：ChenME
 * Date：2017/6/27
 * Email：ibelieve1210@163.com
 */

import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity,
    Switch,
} from 'react-native';

class CommonCellMore extends Component {

    static defaultProps = {
        title: '', // 左侧的文字
        isShowSwitch: false, // 是否显示开关
        rightText: '',

    };

    constructor(props) {
        super(props);
        this.state = {
            switchState: false,
        };
    }

    render() {
        return (
            <TouchableOpacity
                onPress={()=> {
                    alert('点击了');
                }}
            >
                <View style={styles.item}>
                    <Text>{this.props.title}</Text>

                    {this.renderRightView()}
                </View>
            </TouchableOpacity>
        );
    }

    renderRightView() {
        return this.props.isShowSwitch ?
            <Switch
                onValueChange={()=> {
                    this.setState({
                        switchState: !this.state.switchState,
                    });
                }}
                value={this.state.switchState}
            /> :
            <View style={{flexDirection: 'row', alignItems: 'center',}}>
                {this.renderRightText()}
                <Image
                    source={{uri: 'icon_cell_rightarrow'}}
                    style={{width: 8, height: 13}}
                />
            </View>;
    }

    renderRightText() {
        if (this.props.rightText.length > 0) {
            return <Text style={{color: 'gray', marginRight: 3}}>{this.props.rightText}</Text>
        }
    }
}

const styles = StyleSheet.create({
    item: {
        flexDirection: 'row',
        height: 40,
        backgroundColor: '#fff',
        borderBottomColor: '#ddd',
        borderBottomWidth: 0.5,
        justifyContent: 'space-between',
        alignItems: 'center',
        paddingHorizontal: 10,
    }
});

export {CommonCellMore};